home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d13 / ptv2n1.arc / DEC2HEX.PAS < prev    next >
Pascal/Delphi Source File  |  1991-03-26  |  623b  |  22 lines

  1. { This constant definition is required by both Dec2Hex }
  2. { and Hex2Dec: }
  3.  
  4. CONST
  5.   HexString : array [0..15] of char = '0123456789ABCDEF';
  6.  
  7. FUNCTION Dec2Hex (Num : word) : string;
  8. { Returns decimal value as hex string }
  9. VAR
  10.   Loop  : Byte;
  11.   S     : string [10];
  12.  
  13. BEGIN
  14.   S := '';                                 { empty string }   
  15.   for Loop := 1 to 4 do begin              { do 4 chars }
  16.     S := HexString [Lo (Num) and $F] + S;  { use 4 lowest bits } 
  17.     Num := Num shr 4;                      { shift bits right 4 } 
  18.     end;
  19.   Dec2Hex := '$' + S;                      { return string } 
  20. END;
  21.  
  22.